/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.elec.caculate.web;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.elec.caculate.entity.ElecEarningsCalculate;
import cn.net.ecode.elec.caculate.service.ElecEarningsCalculateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 收益测算Controller
 * @author AlanShelby
 * @version 2019-09-06
 */
@Controller
@RequestMapping(value = "${adminPath}/caculate/elecEarningsCalculate")
public class ElecEarningsCalculateController extends BaseController {

	@Autowired
	private ElecEarningsCalculateService elecEarningsCalculateService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecEarningsCalculate get(String id, boolean isNewRecord) {
		return elecEarningsCalculateService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("caculate:elecEarningsCalculate:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecEarningsCalculate elecEarningsCalculate, Model model) {
		model.addAttribute("elecEarningsCalculate", elecEarningsCalculate);
		return "elec/caculate/elecEarningsCalculateList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("caculate:elecEarningsCalculate:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecEarningsCalculate> listData(ElecEarningsCalculate elecEarningsCalculate, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecEarningsCalculate> page = elecEarningsCalculateService.findPage(new Page<ElecEarningsCalculate>(request, response), elecEarningsCalculate);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("caculate:elecEarningsCalculate:view")
	@RequestMapping(value = "form")
	public String form(ElecEarningsCalculate elecEarningsCalculate, Model model) {
		model.addAttribute("elecEarningsCalculate", elecEarningsCalculate);
		return "elec/caculate/elecEarningsCalculateForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("caculate:elecEarningsCalculate:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecEarningsCalculate elecEarningsCalculate) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecEarningsCalculate)){
			return renderResult(Global.FALSE, message);
		}
		elecEarningsCalculateService.save(elecEarningsCalculate);
		return renderResult(Global.TRUE, "保存收益测算成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("caculate:elecEarningsCalculate:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecEarningsCalculate elecEarningsCalculate) {
		elecEarningsCalculateService.delete(elecEarningsCalculate);
		return renderResult(Global.TRUE, "删除收益测算成功！");
	}

}